package com.xwy.usercenter.once;

import com.xwy.usercenter.mapper.UserMapper;
import com.xwy.usercenter.model.User;
import com.xwy.usercenter.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StopWatch;

import java.util.ArrayList;
import java.util.List;

@Component
public class InsertUsers {
    @Autowired
    private UserService userService;

    //@Scheduled(initialDelay = 5000, fixedRate = Long.MAX_VALUE)
    public void doInsertUser(){
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        final int USER_SIZE = 10;
        List<User> userList = new ArrayList<>();
        for (int i = 0; i < USER_SIZE; i++) {
            User user = new User();
            user.setUsername("假数据");
            user.setUserAccount("jiashuju");
            user.setAvatarUrl("shanghai.myqcloud.com/shayu931/shayu.png");
            user.setProfile("一条咸鱼");
            user.setGender((byte) 0);
            user.setUserPassword("12345678");
            user.setPhone("123456789108");
            user.setEmail("qq-qq@qq.com");
            user.setUserStatus((byte) 0);
            user.setUserRole(0);
            user.setPlanetCode("1234");
            user.setTags("[]");
            userList.add(user);
        }
        userService.saveBatch(userList, 10);
        stopWatch.stop();
        System.out.println( stopWatch.getLastTaskTimeMillis());
    }
}


